import { defineStore } from 'pinia';
import _ from 'lodash';
import Data from './dataList';
import type * as Type from './type';
import type * as ApiType from '@/api/processClient/processClient.d';

const useProcessHeader = defineStore('PrHeader', {
  state: (): Type.PrHeaderState => ({
    currentId: 0,
    queryToolList: [],
    markToolList: []
  }),
  actions: {
    getTypeList(id: number, type: boolean = false) {
      if (this.currentId === id) {
        this.currentId = 0;
      } else {
        this.currentId = id;
      }
      if (id === 3) {
        this.currentId = 0;
      }
      if (type) {
        // 为true是查看工具
        return this.queryToolList.filter(item => item.id === id)[0];
      } else {
        // 为false是标注工具
        return this.markToolList.filter(item => item.id === id)[0];
      }
    },
    // 派发当前state数据
    setDataList(partial: Partial<Type.PrHeaderState>) {
      this.$patch(partial);
    },
    // 根据类型获取过滤数据
    getToolList(type: string) {
      const result: Type.PrHeaderState = {
        currentId: 0,
        queryToolList: [],
        markToolList: []
      }
      const includes = ['pic', 'mpr', 'mp4'].includes(type);
      if (includes) {
        result.queryToolList = Data.queryList.filter(item => item.type.includes(type));
        result.markToolList = Data.markList.filter(item => item.type.includes(type));
      } else {
        result.queryToolList = _.cloneDeep(Data.queryList);
        result.markToolList = _.cloneDeep(Data.markList);
      }
      this.setDataList(result);
    },
    setData(values: Array<Type.ToolLesionItem & ApiType.AuditTaskImageResultList>, key: string) {
      this.markToolList = this.markToolList.map(item => {
        if (item.toolType === key) {
          item.lesionList = values;
        } 
        return item;
      });
    }
  }
})

export default useProcessHeader;